﻿using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace ALinq.BBS.Business
{
    public partial class Board
	{
        private ICollection<ValidationResult> validationResults;
        
        partial void OnValidate(ChangeAction action)
        {
            var vc = new ValidationContext(this, null, null);
            ValidationResults.Clear();
            Validator.TryValidateObject(this, vc, ValidationResults);
            if(ValidationResults.Count > 0)
                throw new ValidationException();
        }

        public ICollection<ValidationResult> ValidationResults
        {
            get
            {
                if (validationResults == null)
                    validationResults = new List<ValidationResult>();

                return validationResults;
            }
        }

		void SetDataContext(DataContext dataContext)
		{
			this.DataContext = (Database)dataContext;
		}

		internal Database DataContext { get; private set; }
	}
	partial class User
	{
        private ICollection<ValidationResult> validationResults;
        
        partial void OnValidate(ChangeAction action)
        {
            var vc = new ValidationContext(this, null, null);
            Validator.TryValidateObject(this, vc, ValidationResults);
            if(ValidationResults.Count > 0)
                throw new ValidationException();
        }

        public ICollection<ValidationResult> ValidationResults
        {
            get
            {
                if (validationResults == null)
                    validationResults = new List<ValidationResult>();

                return validationResults;
            }
        }

		void SetDataContext(DataContext dataContext)
		{
			this.DataContext = (Database)dataContext;
		}

		internal Database DataContext { get; private set; }
	}
	partial class PostFavor
	{
        private ICollection<ValidationResult> validationResults;
        
        partial void OnValidate(ChangeAction action)
        {
            var vc = new ValidationContext(this, null, null);
            Validator.TryValidateObject(this, vc, ValidationResults);
            if(ValidationResults.Count > 0)
                throw new ValidationException();
        }

        public ICollection<ValidationResult> ValidationResults
        {
            get
            {
                if (validationResults == null)
                    validationResults = new List<ValidationResult>();

                return validationResults;
            }
        }

		void SetDataContext(DataContext dataContext)
		{
			this.DataContext = (Database)dataContext;
		}

		internal Database DataContext { get; private set; }
	}
	partial class TopPost
	{
        private ICollection<ValidationResult> validationResults;
        
        partial void OnValidate(ChangeAction action)
        {
            var vc = new ValidationContext(this, null, null);
            Validator.TryValidateObject(this, vc, ValidationResults);
            if(ValidationResults.Count > 0)
                throw new ValidationException();
        }

        public ICollection<ValidationResult> ValidationResults
        {
            get
            {
                if (validationResults == null)
                    validationResults = new List<ValidationResult>();

                return validationResults;
            }
        }

		void SetDataContext(DataContext dataContext)
		{
			this.DataContext = (Database)dataContext;
		}

		internal Database DataContext { get; private set; }
	}
	partial class ObjectIdentity
	{
        private ICollection<ValidationResult> validationResults;
        
        partial void OnValidate(ChangeAction action)
        {
            var vc = new ValidationContext(this, null, null);
            Validator.TryValidateObject(this, vc, ValidationResults);
            if(ValidationResults.Count > 0)
                throw new ValidationException();
        }

        public ICollection<ValidationResult> ValidationResults
        {
            get
            {
                if (validationResults == null)
                    validationResults = new List<ValidationResult>();

                return validationResults;
            }
        }

		void SetDataContext(DataContext dataContext)
		{
			this.DataContext = (Database)dataContext;
		}

		internal Database DataContext { get; private set; }
	}
}